package com.example.springboot.common;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor())  // 配置jwt的拦截器规则
                .addPathPatterns("/**")            // 拦截所有的请求路径
                .excludePathPatterns("/login",     // 放行以下接口
                        "/file/**",
                        "/book/**",
                        "/category/**",
                        "/carousel/**",
                        "/collect/**",
                        "/borrow/**",
                        "/comment/**",
                        "/notice");
        super.addInterceptors(registry);
    }

    @Bean
    public JwtInterceptor jwtInterceptor() {
        return new JwtInterceptor();
    }

}
